{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };var element = document.getElementById(\"1001\");\n",
       "  if (element == null) {\n",
       "    console.error(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n",
       "    return false;\n",
       "  }\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.4.0.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };var element = document.getElementById(\"1001\");\n  if (element == null) {\n    console.error(\"Bokeh: ERROR: autoload.js configured with elementid '1001' but no matching script tag was found. \")\n    return false;\n  }\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-1.4.0.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-1.4.0.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import xlrd\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from math import radians, cos, sin, asin, sqrt\n",
    "import xlwt\n",
    "import operator\n",
    "import copy\n",
    "from functools import reduce\n",
    "import sklearn.cluster as sc\n",
    "import re\n",
    "import bokeh\n",
    "from bokeh.io import output_notebook, show\n",
    "from bokeh.plotting import figure\n",
    "output_notebook() #导入这个命令之后bokeh的绘画内容都在notebook上显示\n",
    "\n",
    "# 不用科学计数\n",
    "pd.set_option('display.float_format',lambda x : '%.2f' % x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSN</th>\n",
       "      <th>StateCode</th>\n",
       "      <th>Year</th>\n",
       "      <th>Data</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ABICB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1960</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ABICB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1961</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ABICB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1962</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ABICB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1963</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ABICB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1964</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105739</th>\n",
       "      <td>WYTCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>2005</td>\n",
       "      <td>42367.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105740</th>\n",
       "      <td>WYTCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>2006</td>\n",
       "      <td>66164.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105741</th>\n",
       "      <td>WYTCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>2007</td>\n",
       "      <td>89019.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105742</th>\n",
       "      <td>WYTCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>2008</td>\n",
       "      <td>159881.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105743</th>\n",
       "      <td>WYTCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>2009</td>\n",
       "      <td>195454.77</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>105744 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          MSN StateCode  Year      Data\n",
       "0       ABICB        AZ  1960      0.00\n",
       "1       ABICB        AZ  1961      0.00\n",
       "2       ABICB        AZ  1962      0.00\n",
       "3       ABICB        AZ  1963      0.00\n",
       "4       ABICB        AZ  1964      0.00\n",
       "...       ...       ...   ...       ...\n",
       "105739  WYTCB        TX  2005  42367.85\n",
       "105740  WYTCB        TX  2006  66164.84\n",
       "105741  WYTCB        TX  2007  89019.09\n",
       "105742  WYTCB        TX  2008 159881.36\n",
       "105743  WYTCB        TX  2009 195454.77\n",
       "\n",
       "[105744 rows x 4 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# load data\n",
    "excel_origin=pd.ExcelFile('ProblemCData.xlsx')# 原始数据\n",
    "data_origin=pd.read_excel(excel_origin,'seseds')\n",
    "data_origin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_AZ=data_origin[data_origin['StateCode']=='AZ']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PART I\n",
    "## 处理数据\n",
    "发现缺失数据与冗余数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_origin_MSN=data_origin['MSN']\n",
    "#nodup=data_origin_MSN[-data_origin_MSN.duplicated()]# 去除重复项\n",
    "nodup=data_origin_MSN.drop_duplicates()# 二者都可\n",
    "\n",
    "nodup_List=list(nodup)\n",
    "MSN_origin=pd.read_excel(excel_origin,'msncodes')\n",
    "MSN_origin=MSN_origin['MSN']\n",
    "MSN_origin_list=list(MSN_origin)\n",
    "\n",
    "invalid_MSN=[x for x in MSN_origin_list if x not in nodup_List]# in MSNcoeds but not in seseds\n",
    "\n",
    "new=invalid_MSN+nodup_List\n",
    "invalid_2=[x for x in new if x not in MSN_origin_list] # in seseds but not in MSNcoeds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 指标分析\n",
    "可以建立以下几种图：（对于每一个州）\n",
    "- 各个部门中各种能源的占比\n",
    "- 各种能源消耗总量\n",
    "    - 石油\n",
    "    - 电力\n",
    "    - 煤炭\n",
    "    - 生物质能等\n",
    "    \n",
    "消耗量：\n",
    "\n",
    "- ARTCB 沥青、道路油总消耗量\n",
    "- AVTCB 航空汽油消耗\n",
    "- BMTCB 生物质能总消耗\n",
    "- CLTCB 煤炭总消耗量\n",
    "- DFTCB 蒸馏燃料油总消耗\n",
    "- EMTCB 乙醇燃料不包括变性剂总消耗\n",
    "- ENTCP 乙醇燃料包括变性剂总消耗（单位要转换）\n",
    "- ESTCB 电力总消耗量（即销售）\n",
    "- FFTCB 化石燃料总消耗量\n",
    "- GDPRX 实际GDP（选用实际GDP，剔除通胀的影响）\n",
    "- GETCB 地热\n",
    "- JFTCB 喷气燃料总消耗\n",
    "- JKTCB 煤油型喷气燃料的总消耗量\n",
    "- JNTCB 石脑油型喷气燃料总消耗量\n",
    "- KSTCB 煤油总\n",
    "- LGTCB 液化石油气\n",
    "- LUTCB 润滑油总消费\n",
    "- MGTCB 汽车用油总消耗\n",
    "- NGTCB 天然气总消耗量（包括补充的气体燃料）\n",
    "- NNTCB 天然气总消耗量(不包括补充的气体燃料)\n",
    "- P1TCB 沥青和道路用油、航空汽油、煤油、润滑油等“其他石油产品”的总消耗量\n",
    "- PATCB 所有石油产品的总消耗量\n",
    "- PCTCB 石油焦总消耗量\n",
    "- PMTCB 所有石油产品的总消耗量，不包括燃料乙醇\n",
    "- POTCB 其他石油产品总消费量\n",
    "- RETCB 可再生能源总消耗量\n",
    "- RFTCB 剩余燃料油总消耗量\n",
    "- SOTCB 光伏和太阳能热能总消耗\n",
    "- TETCB 能源消耗总量\n",
    "- WWTCB 木材和废物的总消耗量\n",
    "- TETPB 人均能源消费总量\n",
    "> 注：有总消耗量和最终用途总消耗量两个指标,是不是可以借此计算利用率？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 曲线图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 能源消耗总量\n",
    "data_AZ_TETCB=data_AZ[data_AZ['MSN']=='TETCB']\n",
    "#所有石油\n",
    "data_AZ_PATCB=data_AZ[data_AZ['MSN']=='PATCB']\n",
    "\n",
    "# 可再生能源\n",
    "data_AZ_RETCB=data_AZ[data_AZ['MSN']=='RETCB']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"b29dcb81-9558-42fd-a87e-020fab081abe\" data-root-id=\"1002\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"7083a67a-466b-407f-bd04-ab334c531feb\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1013\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"1017\",\"type\":\"Grid\"},{\"id\":\"1022\",\"type\":\"Grid\"},{\"id\":\"1047\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"1018\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"1039\",\"type\":\"GlyphRenderer\"},{\"id\":\"1052\",\"type\":\"GlyphRenderer\"},{\"id\":\"1066\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1003\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1029\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"1005\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"1009\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"1007\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1011\",\"type\":\"LinearScale\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1059\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1038\",\"type\":\"Line\"},{\"attributes\":{\"callback\":null},\"id\":\"1007\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1060\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1036\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1037\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1038\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1040\",\"type\":\"CDSView\"}},\"id\":\"1039\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"label\":{\"value\":\"\\u6240\\u6709\\u77f3\\u6cb9\\u4ea7\\u54c1\\u7684\\u603b\\u6d88\\u8017\\u91cf\"},\"renderers\":[{\"id\":\"1052\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1062\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1011\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1043\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"1014\",\"type\":\"BasicTicker\"}},\"id\":\"1013\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"1036\",\"type\":\"ColumnDataSource\"}},\"id\":\"1040\",\"type\":\"CDSView\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"YM0Bgq6q4UBX7C+7ViHhQNUEUfer3OBA1PGYgaYF4UBfDOVE2rvgQG2oGOfgdehAuHU3T3pZ7EBBmrFo1YzrQJLLf0gL/O5AZK93/wCQ8EAVAOOZctPwQMk88geEGfJAnBa86Etb8kBOl8VER1/zQNPZyWChCPRA/TBCeBXA80Bwtrmxx5z0QO7O2u0NevJAl5APett/80CM1lFVXF30QCv2l91mTP1AObnfoXCa9kAv3SSGhS/3QAWjkjr4ewVBEoPAyvoMB0EUrkdhA/UEQVZ9rjb2XwVBZDvfT5kO/kAYfQXp1Bv4QDAqqRMdy/hABwjm6AUm90B1jgHZwrD1QBKDwMqPYvVAzZIANes+9UBJumbyTQf3QLbz/dQK9PlAXdxGA6Lg+0ClvcGXt4gBQelILv8hUP9Av30dOHVz/EC7Jw8LHw75QHnpJrEMpPZAsDiceZeM9UC/1M8bCNL0QAHBHL35NvRAs3vysJmU9kA/jBAeInX3QMmrc4zf8fdAfdCzWZpi+0Akl/+QVET5QA==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"1090\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1089\",\"type\":\"UnionRenderers\"}},\"id\":\"1063\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"line_color\":\"green\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1064\",\"type\":\"Line\"},{\"attributes\":{\"text\":\"A Z\"},\"id\":\"1003\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1014\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1065\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1043\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1079\",\"type\":\"NumeralTickFormatter\"},\"ticker\":{\"id\":\"1019\",\"type\":\"BasicTicker\"}},\"id\":\"1018\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"1063\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1064\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1065\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1067\",\"type\":\"CDSView\"}},\"id\":\"1066\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1046\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"1019\",\"type\":\"BasicTicker\"}},\"id\":\"1022\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1063\",\"type\":\"ColumnDataSource\"}},\"id\":\"1067\",\"type\":\"CDSView\"},{\"attributes\":{\"items\":[{\"id\":\"1048\",\"type\":\"LegendItem\"},{\"id\":\"1062\",\"type\":\"LegendItem\"},{\"id\":\"1078\",\"type\":\"LegendItem\"}],\"location\":\"top_center\"},\"id\":\"1047\",\"type\":\"Legend\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1023\",\"type\":\"PanTool\"},{\"id\":\"1024\",\"type\":\"WheelZoomTool\"},{\"id\":\"1025\",\"type\":\"BoxZoomTool\"},{\"id\":\"1026\",\"type\":\"SaveTool\"},{\"id\":\"1027\",\"type\":\"ResetTool\"},{\"id\":\"1028\",\"type\":\"HelpTool\"}]},\"id\":\"1029\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1075\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"label\":{\"value\":\"\\u603b\\u80fd\\u6e90\\u6d88\\u8017\"},\"renderers\":[{\"id\":\"1039\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1048\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1076\",\"type\":\"Selection\"},{\"attributes\":{\"ticker\":{\"id\":\"1014\",\"type\":\"BasicTicker\"}},\"id\":\"1017\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"t2J/2eJHEUGI9NuXKJ0SQYv9Zfd01xNB3gIJSgJFFUGYTBWM0pIWQbMMcSxx6RZBI0p7gyGiGEEU0ERYq0wZQQIrh9ZQ1xtByXa+nwpoHkGyLm6jwsIfQayt2H916SBBmG4SI5/PIkG1pnmH5HIkQbfRAJ5ZoyRBsi5uYzUkJEGamZn5Qx0lQYj023dmjCZBzhlR2kbTJkFMN4kBr/8nQc6qz/U0BidBjnVx+74KKEEZ4lj378YmQT9XWzFjICdBAU2E7WZ9KEHcRgNYMLkpQaOSOkGzBipBfGEy1f1qKkF6Nqv+i6grQWKh1tThxyxBOGdE6fPzLEEhsHKooTstQSPb+Z7VBS5BBoGVgx6cLkE1XrrpvxkwQXNokS33lDBBMQisnHmRMUE730/tER4yQeOlm+Rc/DJB5/upcSSrM0E1XrpJvlg0QVyPwhXJYzRBQmDl8HuSNEESg8AKKNY0QXsUrucA2TVBDi2yPYOQNkGR7Xy/pVo3Qarx0q1p+jdBAiuH1nOTN0G28/106TA2QQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"1060\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1059\",\"type\":\"UnionRenderers\"}},\"id\":\"1036\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"\\u53ef\\u518d\\u751f\\u80fd\\u6e90\\u603b\\u6d88\\u8017\\u91cf\"},\"renderers\":[{\"id\":\"1066\",\"type\":\"GlyphRenderer\"}]},\"id\":\"1078\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"gnNGlH+o/UB0RpT21fv+QBsv3aRXlwBB5BQdyRihAUF88rBQRwYCQYnS3mDFzwFBat5xCslzA0F2Tx4WBIEEQcxdS8gxBgdB+zpwzheUCEECvAUSkggKQQ4tsp3u/wpBV+wvu5PdD0HJ5T9kpeITQcBbIAFF4RNBWmQ7H9e4EkEpXI+CWMISQfVKWYZgbhVB46WbhDrPFUGBBMVPsBkVQaTfvo4AYxJBlWWIY8NaEUFrK/aXw/wQQRKlvQFPoxFBc2iRbaEHE0E3GsCbs1cTQT81XrpHahRBokW284LcFEFBguIHNzcVQYV80LP3hBVBHHxhct4vFUE/V1txUqMVQV3+Q/pNSRZBRPrta9hAF0GUh4WaJcAXQbaEfNBQCxlB+MJkKpTbGkGDwMrhv+oaQS0hH3Q+Mx1BHcnlv83KHkH1SllG3k0fQT81XnrqoB9Bc2iRjYEoIEGJQWCF+mMgQcuhRRb0LCFBW7G/bHULIkHu68D59mAiQU3zjvPtMSJBiIVaU/qjIUHHKTqy4nwgQQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"1076\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1075\",\"type\":\"UnionRenderers\"}},\"id\":\"1049\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1079\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{\"line_color\":\"orange\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1050\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1037\",\"type\":\"Line\"},{\"attributes\":{\"overlay\":{\"id\":\"1046\",\"type\":\"BoxAnnotation\"}},\"id\":\"1025\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1051\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1089\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1026\",\"type\":\"SaveTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1049\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1050\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1051\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"1053\",\"type\":\"CDSView\"}},\"id\":\"1052\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1090\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1027\",\"type\":\"ResetTool\"},{\"attributes\":{\"source\":{\"id\":\"1049\",\"type\":\"ColumnDataSource\"}},\"id\":\"1053\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1028\",\"type\":\"HelpTool\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"7083a67a-466b-407f-bd04-ab334c531feb\",\"roots\":{\"1002\":\"b29dcb81-9558-42fd-a87e-020fab081abe\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1002"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#import bokeh.core.enums.LegendLocation\n",
    "from bokeh.models import NumeralTickFormatter\n",
    "\n",
    "p=figure(title=\"AZ州\",plot_width=600,plot_height=400)\n",
    "\n",
    "#p.yaxis[0].formatter=BasicTickFormatter()\n",
    "#p.yaxis[0].formatter.use_scientific==False\n",
    "\n",
    "p.line(data_AZ_TETCB['Year'],data_AZ_TETCB['Data'],line_color='red',legend='总能源消耗')\n",
    "p.line(data_AZ_PATCB['Year'],data_AZ_PATCB['Data'],line_color=\"orange\",legend='所有石油产品的总消耗量')\n",
    "p.line(data_AZ_RETCB['Year'],data_AZ_RETCB['Data'],line_color=\"green\",legend='可再生能源总消耗量')\n",
    "p.legend.location= \"top_center\" \n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 四个州能源消耗总趋势图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_AZ=data_origin[data_origin['StateCode']=='AZ']\n",
    "data_NM=data_origin[data_origin['StateCode']=='NM']\n",
    "data_CA=data_origin[data_origin['StateCode']=='CA']\n",
    "data_TX=data_origin[data_origin['StateCode']=='TX']\n",
    "data_AZ_TETCB=data_AZ[data_AZ['MSN']=='TETCB']\n",
    "data_NM_TETCB=data_NM[data_NM['MSN']=='TETCB']\n",
    "data_CA_TETCB=data_CA[data_CA['MSN']=='TETCB']\n",
    "data_TX_TETCB=data_TX[data_TX['MSN']=='TETCB']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"691ad59a-9ed6-4a48-9f4d-c9db253b077c\" data-root-id=\"9574\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"697a5a0b-0c4a-44b5-bde8-de1338208ef9\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"9585\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"9589\",\"type\":\"Grid\"},{\"id\":\"9594\",\"type\":\"Grid\"},{\"id\":\"9619\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"9590\",\"type\":\"LinearAxis\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"9611\",\"type\":\"GlyphRenderer\"},{\"id\":\"9624\",\"type\":\"GlyphRenderer\"},{\"id\":\"9638\",\"type\":\"GlyphRenderer\"},{\"id\":\"9654\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"9575\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"9601\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"9577\",\"type\":\"DataRange1d\"},\"x_scale\":{\"id\":\"9581\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"9579\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"9583\",\"type\":\"LinearScale\"}},\"id\":\"9574\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"9608\",\"type\":\"ColumnDataSource\"}},\"id\":\"9612\",\"type\":\"CDSView\"},{\"attributes\":{\"ticker\":{\"id\":\"9586\",\"type\":\"BasicTicker\"}},\"id\":\"9589\",\"type\":\"Grid\"},{\"attributes\":{\"line_color\":\"#2ca02c\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9636\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"9669\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"9595\",\"type\":\"PanTool\"},{\"id\":\"9596\",\"type\":\"WheelZoomTool\"},{\"id\":\"9597\",\"type\":\"BoxZoomTool\"},{\"id\":\"9598\",\"type\":\"SaveTool\"},{\"id\":\"9599\",\"type\":\"ResetTool\"},{\"id\":\"9600\",\"type\":\"HelpTool\"}]},\"id\":\"9601\",\"type\":\"Toolbar\"},{\"attributes\":{\"data_source\":{\"id\":\"9635\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9636\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"9637\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"9639\",\"type\":\"CDSView\"}},\"id\":\"9638\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"items\":[{\"id\":\"9620\",\"type\":\"LegendItem\"},{\"id\":\"9634\",\"type\":\"LegendItem\"},{\"id\":\"9650\",\"type\":\"LegendItem\"},{\"id\":\"9668\",\"type\":\"LegendItem\"}],\"location\":\"top_left\"},\"id\":\"9619\",\"type\":\"Legend\"},{\"attributes\":{\"source\":{\"id\":\"9621\",\"type\":\"ColumnDataSource\"}},\"id\":\"9625\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"9647\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"9615\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"9608\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9609\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"9610\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"9612\",\"type\":\"CDSView\"}},\"id\":\"9611\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data_source\":{\"id\":\"9651\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9652\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"9653\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"9655\",\"type\":\"CDSView\"}},\"id\":\"9654\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9623\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"9596\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"9940\",\"type\":\"Selection\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9653\",\"type\":\"Line\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"9618\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"label\":{\"value\":\"NM\"},\"renderers\":[{\"id\":\"9624\",\"type\":\"GlyphRenderer\"}]},\"id\":\"9634\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"9600\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"9939\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"9615\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"9586\",\"type\":\"BasicTicker\"}},\"id\":\"9585\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"ZmZmlo1VSkHD9SjshIxLQVpkO7+WbUxB16NwbbL/TUHByqEleyFQQZHtfM8kw1BBmpmZecXEUUHpJjFwAoRSQSGwcig8kVNBz/dT27Z9VEHVeOmOlwlVQWq8dCNX/VVBMQisFLJ5VkGamZnhyiZXQbKd70eFRlZBkxgE/rkXV0GoxkvPsapXQUa28737WVhBPQrXm1LJWEFWDi0SmsdZQWQ735e1EllBdZMYlCJIWEG0yHaWc0VXQW8Sg6BEUVdBmG4Sq14DWUF56SbhZ0VZQeXQIkOW6FhBcT0Kbz+TWkEAAACA4ltbQQIrh7b3aVxBBoGV20LLXEHb+X5aoy9cQX0/Nf7OHFxBz/dTA56IW0GoxksPiRBcQbx0k2gzIVxBZmZmxheAXEHFILCS6ulcQbbz/eyB511B46WbNCfnXUEMAiv/eHheQZHtfC/Pf15BhxbZLsqmXkEbL92Uw09fQY/C9UgozF9B30+NpwLFX0HufD/VGwhgQTMzM3tGHmBBXI/CfRunX0GBlUPD4oleQQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"9666\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"9665\",\"type\":\"UnionRenderers\"}},\"id\":\"9635\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"9651\",\"type\":\"ColumnDataSource\"}},\"id\":\"9655\",\"type\":\"CDSView\"},{\"attributes\":{\"line_color\":\"#d62728\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9652\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"9598\",\"type\":\"SaveTool\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"lIeFGvEUFEHwhcnUdcsUQQBvgcSU/RZBVTAq6cilFkG9Upah5l4WQUMc6+K5mBVB2qz6XIP7FkFqvHRTt+MYQce6uA1ZohpBqaROwIEyGkHwp8YLSQAcQS1DHCtmqRxB30+NVzuhHkHMf0h/SysdQdDVVuwqFx1BVFInINMMHEG1N/gC4REfQcgHPVvD5RxBcoqOpJYDHUF8YTJVhlgdQfXb14FfWR1BxY8xd2/cHEH/snuyE2QcQUymCkZZ2BxBVHQkl58DHUEYJlNF9G8cQQfwFogHyRtBSOF6FDanHUHVeOmmNywfQRlz1zKUWCBBFR3JpRpLIkEAAAAgxxgiQUdy+Q9QAyJBX5hMdUl7IkGlvcFX2ykiQRdIUHwZ3CFBjErqpCTQIkEAb4EEYAckQeSDnk2i0iNBZF3cJsbjI0EJih/jgackQd4CCco2RSRBuycPy+oAJEGh+DGGuPMjQTJVMIqaxCRBNV66ySXHJEGYTBVske8kQZYhjrVPzCVBApoIWzw+JUFd3EYDHXMkQQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"9648\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"9647\",\"type\":\"UnionRenderers\"}},\"id\":\"9621\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"9631\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9609\",\"type\":\"Line\"},{\"attributes\":{\"overlay\":{\"id\":\"9618\",\"type\":\"BoxAnnotation\"}},\"id\":\"9597\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"line_color\":\"#ff7f0e\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9622\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"9591\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"9669\",\"type\":\"NumeralTickFormatter\"},\"ticker\":{\"id\":\"9591\",\"type\":\"BasicTicker\"}},\"id\":\"9590\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"9586\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"9632\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"9621\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"9622\",\"type\":\"Line\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"9623\",\"type\":\"Line\"},\"selection_glyph\":null,\"view\":{\"id\":\"9625\",\"type\":\"CDSView\"}},\"id\":\"9624\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null},\"id\":\"9577\",\"type\":\"DataRange1d\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9637\",\"type\":\"Line\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"tvP9VDzoUEFWDi0yugdRQVK4Ho1SxVFBx0s3CZVzUkGHFtnec+FSQVpkO/8IrVNB2c73I6bbVEHNzMy8gvNVQarx0jXSY1dBc2iR7XXfWEHfT43foN1ZQaabxFDQGltBEFg5FN5/XEGkcD1ai8peQZqZmfHjN15BN4lBgIUYXEGiRbY7t0hdQfLSTWrjgV9BsHJoFaiQYEFSuB6V8hthQTvfT8EeN2FBEFg5fPHbYEHfT43nZ3xfQcl2vr+tYV9B0SLbYXqzYEF1kxhkPdJgQcP1KEjqm2BB46Wb+HIRYUGLbOf3CyhiQSuHFtXhs2JBAiuHSunwYkEK16MM2vFiQY/C9QgKN2NBUrgeTfFlY0GkcD0S5ehjQdejcK0pSGRB7FG4/grmZUF7FK63k5VmQYXrUZBt72ZBKVyP2gZKZkEK16MI/v1mQZqZmSEwqGZBXI/CNVAYZ0EUrkcBWdZmQdejcB0D/mZBPQrXc9gEZkGamZnZkd1mQVyPwrWoBGdBCtej4O5uZkGuR+FSUIxlQQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"9940\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"9939\",\"type\":\"UnionRenderers\"}},\"id\":\"9651\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"9583\",\"type\":\"LinearScale\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"9591\",\"type\":\"BasicTicker\"}},\"id\":\"9594\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"9648\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"9581\",\"type\":\"LinearScale\"},{\"attributes\":{\"callback\":null,\"data\":{\"x\":[1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009],\"y\":{\"__ndarray__\":\"t2J/2eJHEUGI9NuXKJ0SQYv9Zfd01xNB3gIJSgJFFUGYTBWM0pIWQbMMcSxx6RZBI0p7gyGiGEEU0ERYq0wZQQIrh9ZQ1xtByXa+nwpoHkGyLm6jwsIfQayt2H916SBBmG4SI5/PIkG1pnmH5HIkQbfRAJ5ZoyRBsi5uYzUkJEGamZn5Qx0lQYj023dmjCZBzhlR2kbTJkFMN4kBr/8nQc6qz/U0BidBjnVx+74KKEEZ4lj378YmQT9XWzFjICdBAU2E7WZ9KEHcRgNYMLkpQaOSOkGzBipBfGEy1f1qKkF6Nqv+i6grQWKh1tThxyxBOGdE6fPzLEEhsHKooTstQSPb+Z7VBS5BBoGVgx6cLkE1XrrpvxkwQXNokS33lDBBMQisnHmRMUE730/tER4yQeOlm+Rc/DJB5/upcSSrM0E1XrpJvlg0QVyPwhXJYzRBQmDl8HuSNEESg8AKKNY0QXsUrucA2TVBDi2yPYOQNkGR7Xy/pVo3Qarx0q1p+jdBAiuH1nOTN0G28/106TA2QQ==\",\"dtype\":\"float64\",\"shape\":[50]}},\"selected\":{\"id\":\"9632\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"9631\",\"type\":\"UnionRenderers\"}},\"id\":\"9608\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"9599\",\"type\":\"ResetTool\"},{\"attributes\":{\"source\":{\"id\":\"9635\",\"type\":\"ColumnDataSource\"}},\"id\":\"9639\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"AZ\"},\"renderers\":[{\"id\":\"9611\",\"type\":\"GlyphRenderer\"}]},\"id\":\"9620\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null},\"id\":\"9579\",\"type\":\"DataRange1d\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"9610\",\"type\":\"Line\"},{\"attributes\":{\"label\":{\"value\":\"CA\"},\"renderers\":[{\"id\":\"9638\",\"type\":\"GlyphRenderer\"}]},\"id\":\"9650\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"TX\"},\"renderers\":[{\"id\":\"9654\",\"type\":\"GlyphRenderer\"}]},\"id\":\"9668\",\"type\":\"LegendItem\"},{\"attributes\":{\"text\":\"five states\"},\"id\":\"9575\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"9666\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"9665\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"9595\",\"type\":\"PanTool\"}],\"root_ids\":[\"9574\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"697a5a0b-0c4a-44b5-bde8-de1338208ef9\",\"roots\":{\"9574\":\"691ad59a-9ed6-4a48-9f4d-c9db253b077c\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "9574"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#import bokeh.core.enums.LegendLocation\n",
    "from bokeh.models import NumeralTickFormatter\n",
    "from bokeh.palettes import Category20\n",
    "\n",
    "p=figure(title=\"five states\",plot_width=600,plot_height=400)\n",
    "\n",
    "#p.yaxis[0].formatter=BasicTickFormatter()\n",
    "#p.yaxis[0].formatter.use_scientific==False\n",
    "\n",
    "p.line(data_AZ_TETCB['Year'],data_AZ_TETCB['Data'],line_color=Category20[8][0],legend='AZ',line_width=3)\n",
    "#p.line(data_AZ_PATCB['Year'],data_AZ_PATCB['Data'],line_color=\"orange\",legend='所有石油产品的总消耗量')\n",
    "#p.line(data_AZ_RETCB['Year'],data_AZ_RETCB['Data'],line_color=\"green\",legend='可再生能源总消耗量')\n",
    "p.line(data_NM_TETCB['Year'],data_NM_TETCB['Data'],line_color=Category20[8][2],legend='NM',line_width=3)\n",
    "p.line(data_CA_TETCB['Year'],data_CA_TETCB['Data'],line_color=Category20[8][4],legend='CA',line_width=3)\n",
    "p.line(data_TX_TETCB['Year'],data_TX_TETCB['Data'],line_color=Category20[8][6],legend='TX',line_width=3)\n",
    "\n",
    "p.legend.location= \"top_left\" \n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 四个州人均能源消耗趋势图\n",
    "略"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 柱状图\n",
    "### 1960年为例各个州的能源消耗柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_1960=data_origin[data_origin['Year']==1960]\n",
    "data_1960_TETCB=data_1960[data_1960['MSN']=='TETCB']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"2f235baa-b9c1-4b75-8226-211f44631e0d\" data-root-id=\"1158\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"6a70e119-4cd1-4d2c-86aa-a2434b2288ec\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1169\",\"type\":\"CategoricalAxis\"}],\"center\":[{\"id\":\"1172\",\"type\":\"Grid\"},{\"id\":\"1177\",\"type\":\"Grid\"}],\"left\":[{\"id\":\"1173\",\"type\":\"LinearAxis\"}],\"renderers\":[{\"id\":\"1182\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1159\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"1178\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"1161\",\"type\":\"FactorRange\"},\"x_scale\":{\"id\":\"1165\",\"type\":\"CategoricalScale\"},\"y_range\":{\"id\":\"1163\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"1167\",\"type\":\"LinearScale\"}},\"id\":\"1158\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1167\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1165\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"callback\":null,\"factors\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"id\":\"1161\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"1960\"},\"id\":\"1159\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1170\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1201\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"1174\",\"type\":\"BasicTicker\"}},\"id\":\"1177\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1202\",\"type\":\"Selection\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1180\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1199\",\"type\":\"CategoricalTickFormatter\"},\"ticker\":{\"id\":\"1170\",\"type\":\"CategoricalTicker\"}},\"id\":\"1169\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1199\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1179\",\"type\":\"ColumnDataSource\"}},\"id\":\"1183\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1179\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"1180\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1181\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"1183\",\"type\":\"CDSView\"}},\"id\":\"1182\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"1184\",\"type\":\"NumeralTickFormatter\"},\"ticker\":{\"id\":\"1174\",\"type\":\"BasicTicker\"}},\"id\":\"1173\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1181\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"1163\",\"type\":\"DataRange1d\"},{\"attributes\":{\"grid_line_color\":null,\"ticker\":{\"id\":\"1170\",\"type\":\"CategoricalTicker\"}},\"id\":\"1172\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1174\",\"type\":\"BasicTicker\"},{\"attributes\":{\"callback\":null,\"data\":{\"top\":{\"__ndarray__\":\"t2J/2eJHEUFmZmaWjVVKQZSHhRrxFBRBtvP9VDzoUEE=\",\"dtype\":\"float64\",\"shape\":[4]},\"x\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"1202\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"1201\",\"type\":\"UnionRenderers\"}},\"id\":\"1179\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1184\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"1178\",\"type\":\"Toolbar\"}],\"root_ids\":[\"1158\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"6a70e119-4cd1-4d2c-86aa-a2434b2288ec\",\"roots\":{\"1158\":\"2f235baa-b9c1-4b75-8226-211f44631e0d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1158"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data_1960_TETCB\n",
    "p = figure(x_range=list(data_1960_TETCB['StateCode']), plot_height=600, title=\"1960\",\n",
    "           toolbar_location=None, tools=\"\")\n",
    "\n",
    "p.vbar(x=data_1960_TETCB['StateCode'], top=data_1960_TETCB['Data'], width=0.9)\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_1960_AZ=data_1960[data_1960['StateCode']=='AZ']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "283128.7124"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 能源总消耗\n",
    "TETCB=data_1960_AZ[data_1960_AZ['MSN']=='TETCB'].iloc[0,3]\n",
    "TETCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4012.94849"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 木材类\n",
    "WWTCB=data_1960_AZ[data_1960_AZ['MSN']=='WWTCB'].iloc[0,3]\n",
    "WWTCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "121479.9737"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有石油类\n",
    "PATCB=data_1960_AZ[data_1960_AZ['MSN']=='PATCB'].iloc[0,3]\n",
    "PATCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "36181.45337"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可再生能源\n",
    "RETCB=data_1960_AZ[data_1960_AZ['MSN']=='RETCB'].iloc[0,3]\n",
    "RETCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4012.94849"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 生物质\n",
    "BMTCB=data_1960_AZ[data_1960_AZ['MSN']=='BMTCB'].iloc[0,3]\n",
    "BMTCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "209.57935"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 煤炭\n",
    "CLTCB=data_1960_AZ[data_1960_AZ['MSN']=='CLTCB'].iloc[0,3]\n",
    "CLTCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ENTCP 乙醇燃料包括变性剂总消耗（单位要转换）\n",
    "ENTCP=data_1960_AZ[data_1960_AZ['MSN']=='ENTCP'].iloc[0,3]\n",
    "ENTCP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "261964.138"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# FFTCB 化石燃料：煤炭石油天然气等\n",
    "FFTCB=data_1960_AZ[data_1960_AZ['MSN']=='FFTCB'].iloc[0,3]\n",
    "FFTCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "246947.25903000002"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "TETCB-RETCB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MSN</th>\n",
       "      <th>StateCode</th>\n",
       "      <th>Year</th>\n",
       "      <th>Data</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>84532</th>\n",
       "      <td>RETCB</td>\n",
       "      <td>AZ</td>\n",
       "      <td>1960</td>\n",
       "      <td>36181.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84582</th>\n",
       "      <td>RETCB</td>\n",
       "      <td>CA</td>\n",
       "      <td>1960</td>\n",
       "      <td>270161.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84632</th>\n",
       "      <td>RETCB</td>\n",
       "      <td>NM</td>\n",
       "      <td>1960</td>\n",
       "      <td>7373.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84682</th>\n",
       "      <td>RETCB</td>\n",
       "      <td>TX</td>\n",
       "      <td>1960</td>\n",
       "      <td>50154.98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         MSN StateCode  Year      Data\n",
       "84532  RETCB        AZ  1960  36181.45\n",
       "84582  RETCB        CA  1960 270161.09\n",
       "84632  RETCB        NM  1960   7373.06\n",
       "84682  RETCB        TX  1960  50154.98"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_1960_RETCB=data_1960[data_1960['MSN']=='RETCB']\n",
    "data_1960_RETCB"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1960全部能源和可再生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    246947.26\n",
       "1   3181514.09\n",
       "2    321647.22\n",
       "3   4381958.35\n",
       "Name: Data, dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_1960_TETCB.reset_index()['Data']-data_1960_RETCB.reset_index()['Data']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"165ad004-b6cc-4cc4-aaa6-f284bdfc6be4\" data-root-id=\"2128\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"fe138aa9-2f64-453c-919a-638468ab38ab\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2139\",\"type\":\"CategoricalAxis\"}],\"center\":[{\"id\":\"2142\",\"type\":\"Grid\"},{\"id\":\"2147\",\"type\":\"Grid\"},{\"id\":\"2164\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"2143\",\"type\":\"LinearAxis\"}],\"outline_line_color\":{\"value\":null},\"plot_height\":400,\"renderers\":[{\"id\":\"2157\",\"type\":\"GlyphRenderer\"},{\"id\":\"2170\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"2129\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"2148\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2131\",\"type\":\"FactorRange\"},\"x_scale\":{\"id\":\"2135\",\"type\":\"CategoricalScale\"},\"y_range\":{\"id\":\"2133\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"2137\",\"type\":\"LinearScale\"}},\"id\":\"2128\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"2148\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"2166\",\"type\":\"ColumnDataSource\"}},\"id\":\"2171\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"2166\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2168\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"Others\",\"nonselection_glyph\":{\"id\":\"2169\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"2171\",\"type\":\"CDSView\"}},\"id\":\"2170\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2151\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"2152\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"2169\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"Energy in 1960\"},\"id\":\"2129\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2135\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"items\":[{\"id\":\"2165\",\"type\":\"LegendItem\"},{\"id\":\"2179\",\"type\":\"LegendItem\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"2164\",\"type\":\"Legend\"},{\"attributes\":{\"label\":{\"value\":\"Others\"},\"renderers\":[{\"id\":\"2170\",\"type\":\"GlyphRenderer\"}]},\"id\":\"2179\",\"type\":\"LegendItem\"},{\"attributes\":{\"data_source\":{\"id\":\"2153\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2155\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"RETCB\",\"nonselection_glyph\":{\"id\":\"2156\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"2158\",\"type\":\"CDSView\"}},\"id\":\"2157\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"grid_line_color\":null,\"ticker\":{\"id\":\"2140\",\"type\":\"CategoricalTicker\"}},\"id\":\"2142\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2178\",\"type\":\"Selection\"},{\"attributes\":{\"callback\":null,\"factors\":[\"AZ\",\"CA\",\"NM\",\"TX\"],\"range_padding\":0.1},\"id\":\"2131\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"2177\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fields\":[]},\"id\":\"2149\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2149\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"2150\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"2156\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"RETCB\",\"Others\"]},\"id\":\"2152\",\"type\":\"Stack\"},{\"attributes\":{\"callback\":null,\"data\":{\"Others\":{\"__ndarray__\":\"FlJ+EholDkGRfvsK5UVIQbMHWuG8oRNB36EolkG3UEE=\",\"dtype\":\"float64\",\"shape\":[4]},\"RETCB\":[36181.45337,270161.0892,7373.05583,50154.98177],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"2178\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"2177\",\"type\":\"UnionRenderers\"}},\"id\":\"2153\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"2180\",\"type\":\"NumeralTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2144\",\"type\":\"BasicTicker\"}},\"id\":\"2143\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"2151\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2161\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"2133\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"2150\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2254\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"2144\",\"type\":\"BasicTicker\"}},\"id\":\"2147\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2255\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2144\",\"type\":\"BasicTicker\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2151\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"expr\":{\"id\":\"2152\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"2168\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2140\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"2161\",\"type\":\"CategoricalTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2140\",\"type\":\"CategoricalTicker\"}},\"id\":\"2139\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2180\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{\"callback\":null,\"data\":{\"Others\":{\"__ndarray__\":\"FlJ+EholDkGRfvsK5UVIQbMHWuG8oRNB36EolkG3UEE=\",\"dtype\":\"float64\",\"shape\":[4]},\"RETCB\":[36181.45337,270161.0892,7373.05583,50154.98177],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"2255\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"2254\",\"type\":\"UnionRenderers\"}},\"id\":\"2166\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2137\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2149\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#718dbf\"},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"expr\":{\"id\":\"2150\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"2155\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2153\",\"type\":\"ColumnDataSource\"}},\"id\":\"2158\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"RETCB\"},\"renderers\":[{\"id\":\"2157\",\"type\":\"GlyphRenderer\"}]},\"id\":\"2165\",\"type\":\"LegendItem\"}],\"root_ids\":[\"2128\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"fe138aa9-2f64-453c-919a-638468ab38ab\",\"roots\":{\"2128\":\"165ad004-b6cc-4cc4-aaa6-f284bdfc6be4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2128"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 堆叠图\n",
    "#fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "states=['AZ','CA','NM','TX']\n",
    "\n",
    "#years = [\"2015\", \"2016\", \"2017\"]\n",
    "stack = ['RETCB','Others']\n",
    "\n",
    "#colors = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "colors=[\"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "#data = {'fruits' : fruits,\n",
    "#        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "#        '2016'   : [5, 3, 4, 2, 4, 6],\n",
    "#        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "data={'states':states,\n",
    "       'RETCB':list(data_1960_RETCB['Data']),\n",
    "       'Others':data_1960_TETCB.reset_index()['Data']-data_1960_RETCB.reset_index()['Data'],\n",
    "}\n",
    "\n",
    "p = figure(x_range=states, plot_height=400, title=\"Energy in 1960\",\n",
    "           toolbar_location=None, tools=\"\")\n",
    "\n",
    "p.vbar_stack(stack, x='states', width=0.9, color=colors, source=data,\n",
    "             legend_label=stack)\n",
    "\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.axis.minor_tick_line_color = None\n",
    "p.outline_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1960 全部能源，可再生和石油（PATCB）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_1960_PATCB=data_1960[data_1960['MSN']=='PATCB']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"082eb1c4-31aa-46c9-a874-be9853b56134\" data-root-id=\"2746\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"0e8fd5d1-0550-44fe-8bef-aa4f4a6634fc\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2757\",\"type\":\"CategoricalAxis\"}],\"center\":[{\"id\":\"2760\",\"type\":\"Grid\"},{\"id\":\"2765\",\"type\":\"Grid\"},{\"id\":\"2784\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"2761\",\"type\":\"LinearAxis\"}],\"outline_line_color\":{\"value\":null},\"plot_height\":400,\"renderers\":[{\"id\":\"2777\",\"type\":\"GlyphRenderer\"},{\"id\":\"2790\",\"type\":\"GlyphRenderer\"},{\"id\":\"2804\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"2747\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"2766\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2749\",\"type\":\"FactorRange\"},\"x_scale\":{\"id\":\"2753\",\"type\":\"CategoricalScale\"},\"y_range\":{\"id\":\"2751\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"2755\",\"type\":\"LinearScale\"}},\"id\":\"2746\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2921\",\"type\":\"Selection\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"2751\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"2769\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2771\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"2772\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2803\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2753\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"2816\",\"type\":\"NumeralTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2762\",\"type\":\"BasicTicker\"}},\"id\":\"2761\",\"type\":\"LinearAxis\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2767\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#6db577\"},\"line_color\":{\"value\":\"#6db577\"},\"top\":{\"expr\":{\"id\":\"2768\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2775\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2758\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"2773\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2775\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"RETCB\",\"nonselection_glyph\":{\"id\":\"2776\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"2778\",\"type\":\"CDSView\"}},\"id\":\"2777\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2786\",\"type\":\"ColumnDataSource\"}},\"id\":\"2791\",\"type\":\"CDSView\"},{\"attributes\":{\"grid_line_color\":null,\"ticker\":{\"id\":\"2758\",\"type\":\"CategoricalTicker\"}},\"id\":\"2760\",\"type\":\"Grid\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2769\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#6379bf\"},\"line_color\":{\"value\":\"#6379bf\"},\"top\":{\"expr\":{\"id\":\"2770\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2788\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"value\":\"PATCB\"},\"renderers\":[{\"id\":\"2790\",\"type\":\"GlyphRenderer\"}]},\"id\":\"2799\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2781\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2767\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"2768\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2776\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2773\",\"type\":\"ColumnDataSource\"}},\"id\":\"2778\",\"type\":\"CDSView\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"2766\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"data\":{\"Others\":{\"__ndarray__\":\"qjC2kLSh/kBDrWm+fn00QeJw5hdVLQpB+PcZM1qXRUE=\",\"dtype\":\"float64\",\"shape\":[4]},\"PATCB\":[121479.9737,1838667.342,107204.5834,1551953.947],\"RETCB\":[36181.45337,270161.0892,7373.05583,50154.98177],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"2814\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"2813\",\"type\":\"UnionRenderers\"}},\"id\":\"2786\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"callback\":null,\"factors\":[\"AZ\",\"CA\",\"NM\",\"TX\"],\"range_padding\":0.1},\"id\":\"2749\",\"type\":\"FactorRange\"},{\"attributes\":{\"label\":{\"value\":\"Others\"},\"renderers\":[{\"id\":\"2804\",\"type\":\"GlyphRenderer\"}]},\"id\":\"2815\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2797\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"items\":[{\"id\":\"2785\",\"type\":\"LegendItem\"},{\"id\":\"2799\",\"type\":\"LegendItem\"},{\"id\":\"2815\",\"type\":\"LegendItem\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"2784\",\"type\":\"Legend\"},{\"attributes\":{\"text\":\"Energy in 1960\"},\"id\":\"2747\",\"type\":\"Title\"},{\"attributes\":{\"label\":{\"value\":\"RETCB\"},\"renderers\":[{\"id\":\"2777\",\"type\":\"GlyphRenderer\"}]},\"id\":\"2785\",\"type\":\"LegendItem\"},{\"attributes\":{\"fields\":[\"RETCB\",\"PATCB\"]},\"id\":\"2771\",\"type\":\"Stack\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"2762\",\"type\":\"BasicTicker\"}},\"id\":\"2765\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"data\":{\"Others\":{\"__ndarray__\":\"qjC2kLSh/kBDrWm+fn00QeJw5hdVLQpB+PcZM1qXRUE=\",\"dtype\":\"float64\",\"shape\":[4]},\"PATCB\":[121479.9737,1838667.342,107204.5834,1551953.947],\"RETCB\":[36181.45337,270161.0892,7373.05583,50154.98177],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"2921\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"2920\",\"type\":\"UnionRenderers\"}},\"id\":\"2800\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data_source\":{\"id\":\"2800\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2802\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"Others\",\"nonselection_glyph\":{\"id\":\"2803\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"2805\",\"type\":\"CDSView\"}},\"id\":\"2804\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2798\",\"type\":\"Selection\"},{\"attributes\":{\"fields\":[]},\"id\":\"2767\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2762\",\"type\":\"BasicTicker\"},{\"attributes\":{\"callback\":null,\"data\":{\"Others\":{\"__ndarray__\":\"qjC2kLSh/kBDrWm+fn00QeJw5hdVLQpB+PcZM1qXRUE=\",\"dtype\":\"float64\",\"shape\":[4]},\"PATCB\":[121479.9737,1838667.342,107204.5834,1551953.947],\"RETCB\":[36181.45337,270161.0892,7373.05583,50154.98177],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"2798\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"2797\",\"type\":\"UnionRenderers\"}},\"id\":\"2773\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2920\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2769\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"2770\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2789\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"RETCB\",\"PATCB\",\"Others\"]},\"id\":\"2772\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2814\",\"type\":\"Selection\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"2768\",\"type\":\"Stack\"},{\"attributes\":{\"source\":{\"id\":\"2800\",\"type\":\"ColumnDataSource\"}},\"id\":\"2805\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"2771\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"expr\":{\"id\":\"2772\",\"type\":\"Stack\"}},\"width\":{\"value\":0.6},\"x\":{\"field\":\"states\"}},\"id\":\"2802\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2816\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{},\"id\":\"2813\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data_source\":{\"id\":\"2786\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2788\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"PATCB\",\"nonselection_glyph\":{\"id\":\"2789\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"2791\",\"type\":\"CDSView\"}},\"id\":\"2790\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"formatter\":{\"id\":\"2781\",\"type\":\"CategoricalTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2758\",\"type\":\"CategoricalTicker\"}},\"id\":\"2757\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2755\",\"type\":\"LinearScale\"},{\"attributes\":{\"fields\":[\"RETCB\",\"PATCB\"]},\"id\":\"2770\",\"type\":\"Stack\"}],\"root_ids\":[\"2746\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"0e8fd5d1-0550-44fe-8bef-aa4f4a6634fc\",\"roots\":{\"2746\":\"082eb1c4-31aa-46c9-a874-be9853b56134\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2746"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 堆叠图\n",
    "#fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "states=['AZ','CA','NM','TX']\n",
    "\n",
    "#years = [\"2015\", \"2016\", \"2017\"]\n",
    "stack = ['RETCB','PATCB','Others']\n",
    "\n",
    "#colors = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "colors=[\"#6db577\",\"#6379bf\" ,\"#e84d60\"]\n",
    "\n",
    "#data = {'fruits' : fruits,\n",
    "#        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "#        '2016'   : [5, 3, 4, 2, 4, 6],\n",
    "#        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "data={'states':states,\n",
    "       'RETCB':list(data_1960_RETCB['Data']),\n",
    "      'PATCB':list(data_1960_PATCB['Data']),\n",
    "       'Others':data_1960_TETCB.reset_index()['Data']-data_1960_RETCB.reset_index()['Data']-data_1960_PATCB.reset_index()['Data'],\n",
    "}\n",
    "\n",
    "p = figure(x_range=states, plot_height=400, title=\"Energy in 1960\",\n",
    "           toolbar_location=None, tools=\"\")\n",
    "\n",
    "p.vbar_stack(stack, x='states', width=0.6, color=colors, source=data,\n",
    "             legend_label=stack)\n",
    "\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.axis.minor_tick_line_color = None\n",
    "p.outline_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_2009=data_origin[data_origin['Year']==2009]\n",
    "data_2009_TETCB=data_2009[data_2009['MSN']=='TETCB']\n",
    "data_2009_RETCB=data_2009[data_2009['MSN']=='RETCB']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2009全部能源和可再生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"0e3d2832-43f7-4089-86b7-c93fc024d4f6\" data-root-id=\"2982\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"aa8de51f-26ec-4367-87fe-d6338b9bc8e6\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2993\",\"type\":\"CategoricalAxis\"}],\"center\":[{\"id\":\"2996\",\"type\":\"Grid\"},{\"id\":\"3001\",\"type\":\"Grid\"},{\"id\":\"3018\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"2997\",\"type\":\"LinearAxis\"}],\"outline_line_color\":{\"value\":null},\"plot_height\":400,\"renderers\":[{\"id\":\"3011\",\"type\":\"GlyphRenderer\"},{\"id\":\"3024\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"2983\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"3002\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"2985\",\"type\":\"FactorRange\"},\"x_scale\":{\"id\":\"2989\",\"type\":\"CategoricalScale\"},\"y_range\":{\"id\":\"2987\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"2991\",\"type\":\"LinearScale\"}},\"id\":\"2982\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"3015\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"3007\",\"type\":\"ColumnDataSource\"}},\"id\":\"3012\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"3031\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"callback\":null,\"data\":{\"RETCB\":[103493.2854,712704.4602,35635.38371,356634.8206],\"TETCB\":[1454313.457,8005515.051,670094.5064,11297410.59],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"3147\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"3146\",\"type\":\"UnionRenderers\"}},\"id\":\"3020\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3034\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{\"data_source\":{\"id\":\"3020\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"3022\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"TETCB\",\"nonselection_glyph\":{\"id\":\"3023\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"3025\",\"type\":\"CDSView\"}},\"id\":\"3024\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"items\":[{\"id\":\"3019\",\"type\":\"LegendItem\"},{\"id\":\"3033\",\"type\":\"LegendItem\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"3018\",\"type\":\"Legend\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3005\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"expr\":{\"id\":\"3006\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"3022\",\"type\":\"VBar\"},{\"attributes\":{\"fields\":[\"RETCB\",\"TETCB\"]},\"id\":\"3006\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3005\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"3006\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"3023\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3147\",\"type\":\"Selection\"},{\"attributes\":{\"grid_line_color\":null,\"ticker\":{\"id\":\"2994\",\"type\":\"CategoricalTicker\"}},\"id\":\"2996\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3146\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"dimension\":1,\"ticker\":{\"id\":\"2998\",\"type\":\"BasicTicker\"}},\"id\":\"3001\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"start\":0},\"id\":\"2987\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2991\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2998\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fields\":[]},\"id\":\"3003\",\"type\":\"Stack\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"3005\",\"type\":\"Stack\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3003\",\"type\":\"Stack\"}},\"fill_color\":{\"value\":\"#718dbf\"},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"expr\":{\"id\":\"3004\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"3009\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"3015\",\"type\":\"CategoricalTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2994\",\"type\":\"CategoricalTicker\"}},\"id\":\"2993\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2989\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom\":{\"expr\":{\"id\":\"3003\",\"type\":\"Stack\"}},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"expr\":{\"id\":\"3004\",\"type\":\"Stack\"}},\"width\":{\"value\":0.9},\"x\":{\"field\":\"states\"}},\"id\":\"3010\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"value\":\"RETCB\"},\"renderers\":[{\"id\":\"3011\",\"type\":\"GlyphRenderer\"}]},\"id\":\"3019\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"TETCB\"},\"renderers\":[{\"id\":\"3024\",\"type\":\"GlyphRenderer\"}]},\"id\":\"3033\",\"type\":\"LegendItem\"},{\"attributes\":{\"fields\":[\"RETCB\"]},\"id\":\"3004\",\"type\":\"Stack\"},{\"attributes\":{},\"id\":\"2994\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"3032\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"3034\",\"type\":\"NumeralTickFormatter\"},\"minor_tick_line_color\":{\"value\":null},\"ticker\":{\"id\":\"2998\",\"type\":\"BasicTicker\"}},\"id\":\"2997\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"3020\",\"type\":\"ColumnDataSource\"}},\"id\":\"3025\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"3007\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"3009\",\"type\":\"VBar\"},\"hover_glyph\":null,\"muted_glyph\":null,\"name\":\"RETCB\",\"nonselection_glyph\":{\"id\":\"3010\",\"type\":\"VBar\"},\"selection_glyph\":null,\"view\":{\"id\":\"3012\",\"type\":\"CDSView\"}},\"id\":\"3011\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"data\":{\"RETCB\":[103493.2854,712704.4602,35635.38371,356634.8206],\"TETCB\":[1454313.457,8005515.051,670094.5064,11297410.59],\"states\":[\"AZ\",\"CA\",\"NM\",\"TX\"]},\"selected\":{\"id\":\"3032\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"3031\",\"type\":\"UnionRenderers\"}},\"id\":\"3007\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"text\":\"Energy in 2009\"},\"id\":\"2983\",\"type\":\"Title\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\"},\"id\":\"3002\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"factors\":[\"AZ\",\"CA\",\"NM\",\"TX\"],\"range_padding\":0.1},\"id\":\"2985\",\"type\":\"FactorRange\"}],\"root_ids\":[\"2982\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"aa8de51f-26ec-4367-87fe-d6338b9bc8e6\",\"roots\":{\"2982\":\"0e3d2832-43f7-4089-86b7-c93fc024d4f6\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2982"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 堆叠图\n",
    "#fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "states=['AZ','CA','NM','TX']\n",
    "\n",
    "#years = [\"2015\", \"2016\", \"2017\"]\n",
    "stack = ['RETCB','TETCB']\n",
    "\n",
    "#colors = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "colors=[\"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "#data = {'fruits' : fruits,\n",
    "#        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "#        '2016'   : [5, 3, 4, 2, 4, 6],\n",
    "#        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "data={'states':states,\n",
    "       'RETCB':list(data_2009_RETCB['Data']),\n",
    "       'TETCB':list(data_2009_TETCB['Data']),\n",
    "}\n",
    "\n",
    "p = figure(x_range=states, plot_height=400, title=\"Energy in 2009\",\n",
    "           toolbar_location=None, tools=\"\")\n",
    "\n",
    "p.vbar_stack(stack, x='states', width=0.9, color=colors, source=data,\n",
    "             legend_label=stack)\n",
    "\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.axis.minor_tick_line_color = None\n",
    "p.outline_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.yaxis[0].formatter=NumeralTickFormatter()\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 饼状图\n",
    "### 2009年新墨西哥州五大部门能源消耗饼状图\n",
    "- TEACB 运输部门总消耗\n",
    "- TECCB 商业部门总消耗\n",
    "- TEEIB 电力\n",
    "- TEICB 工业\n",
    "- TERCB 住宅"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_2009_NM=data_2009[data_2009['StateCode']=='NM']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"edb3638c-d34b-4115-864e-f9f3fc1b1823\" data-root-id=\"10190\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"1237791b-e362-45ae-9d56-6ca010de8686\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"10201\",\"type\":\"LinearAxis\"}],\"center\":[{\"id\":\"10205\",\"type\":\"Grid\"},{\"id\":\"10210\",\"type\":\"Grid\"},{\"id\":\"10227\",\"type\":\"Legend\"}],\"left\":[{\"id\":\"10206\",\"type\":\"LinearAxis\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"10220\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"10191\",\"type\":\"Title\"},\"toolbar\":{\"id\":\"10212\",\"type\":\"Toolbar\"},\"toolbar_location\":null,\"x_range\":{\"id\":\"10193\",\"type\":\"Range1d\"},\"x_scale\":{\"id\":\"10197\",\"type\":\"LinearScale\"},\"y_range\":{\"id\":\"10195\",\"type\":\"DataRange1d\"},\"y_scale\":{\"id\":\"10199\",\"type\":\"LinearScale\"}},\"id\":\"10190\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"10199\",\"type\":\"LinearScale\"},{\"attributes\":{\"callback\":null},\"id\":\"10195\",\"type\":\"DataRange1d\"},{\"attributes\":{\"grid_line_color\":null,\"ticker\":{\"id\":\"10202\",\"type\":\"BasicTicker\"}},\"id\":\"10205\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"data\":{\"angle\":{\"__ndarray__\":\"BAXDuJQZ8z9BVm8gDhrnPyMbLahKpQJASwrC2/109T9fh/O3fEPmPw==\",\"dtype\":\"float64\",\"shape\":[5]},\"color\":[\"#1f77b4\",\"#aec7e8\",\"#ff7f0e\",\"#ffbb78\",\"#2ca02c\"],\"country\":[\"\\u8fd0\\u8f93\",\"\\u5546\\u4e1a\",\"\\u7535\\u529b\",\"\\u5de5\\u4e1a\",\"\\u4f4f\\u5b85\"],\"index\":[0,1,2,3,4],\"value\":{\"__ndarray__\":\"Xf5Deom0CEFoke18quH9QLRZ9bkeHhhBSnuDLwjBC0GIhVrTIMz8QA==\",\"dtype\":\"float64\",\"shape\":[5]}},\"selected\":{\"id\":\"10506\",\"type\":\"Selection\"},\"selection_policy\":{\"id\":\"10505\",\"type\":\"UnionRenderers\"}},\"id\":\"10216\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"10506\",\"type\":\"Selection\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"10226\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"10207\",\"type\":\"BasicTicker\"},\"visible\":false},\"id\":\"10206\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"tooltips\":\"@country: @value\"},\"id\":\"10211\",\"type\":\"HoverTool\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"10215\",\"type\":\"CumSum\"},\"units\":\"rad\"},\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"value\":\"white\"},\"radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"10214\",\"type\":\"CumSum\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"10218\",\"type\":\"Wedge\"},{\"attributes\":{\"axis_label\":null,\"formatter\":{\"id\":\"10224\",\"type\":\"BasicTickFormatter\"},\"ticker\":{\"id\":\"10202\",\"type\":\"BasicTicker\"},\"visible\":false},\"id\":\"10201\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"10197\",\"type\":\"LinearScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"10211\",\"type\":\"HoverTool\"}]},\"id\":\"10212\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"10224\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"field\":\"angle\",\"include_zero\":true},\"id\":\"10214\",\"type\":\"CumSum\"},{\"attributes\":{\"text\":\"Pie Chart\"},\"id\":\"10191\",\"type\":\"Title\"},{\"attributes\":{\"label\":{\"field\":\"country\"},\"renderers\":[{\"id\":\"10220\",\"type\":\"GlyphRenderer\"}]},\"id\":\"10228\",\"type\":\"LegendItem\"},{\"attributes\":{\"callback\":null,\"start\":-0.5},\"id\":\"10193\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"10202\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"10226\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"10505\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"items\":[{\"id\":\"10228\",\"type\":\"LegendItem\"}]},\"id\":\"10227\",\"type\":\"Legend\"},{\"attributes\":{\"field\":\"angle\"},\"id\":\"10215\",\"type\":\"CumSum\"},{\"attributes\":{\"end_angle\":{\"expr\":{\"id\":\"10215\",\"type\":\"CumSum\"},\"units\":\"rad\"},\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"radius\":{\"units\":\"data\",\"value\":0.4},\"start_angle\":{\"expr\":{\"id\":\"10214\",\"type\":\"CumSum\"},\"units\":\"rad\"},\"x\":{\"value\":0},\"y\":{\"value\":1}},\"id\":\"10219\",\"type\":\"Wedge\"},{\"attributes\":{\"dimension\":1,\"grid_line_color\":null,\"ticker\":{\"id\":\"10207\",\"type\":\"BasicTicker\"}},\"id\":\"10210\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"10216\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"10218\",\"type\":\"Wedge\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"10219\",\"type\":\"Wedge\"},\"selection_glyph\":null,\"view\":{\"id\":\"10221\",\"type\":\"CDSView\"}},\"id\":\"10220\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"10207\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"10216\",\"type\":\"ColumnDataSource\"}},\"id\":\"10221\",\"type\":\"CDSView\"}],\"root_ids\":[\"10190\"]},\"title\":\"Bokeh Application\",\"version\":\"1.4.0\"}};\n",
       "  var render_items = [{\"docid\":\"1237791b-e362-45ae-9d56-6ca010de8686\",\"roots\":{\"10190\":\"edb3638c-d34b-4115-864e-f9f3fc1b1823\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "10190"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from math import pi\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "#from bokeh.io import output_file, show\n",
    "from bokeh.palettes import Category20\n",
    "from bokeh.plotting import figure\n",
    "from bokeh.transform import cumsum\n",
    "\n",
    "x={\n",
    "    '运输':data_2009_NM[data_2009_NM['MSN']=='TEACB'].iloc[0,3],\n",
    "    '商业':data_2009_NM[data_2009_NM['MSN']=='TECCB'].iloc[0,3],\n",
    "    '电力':data_2009_NM[data_2009_NM['MSN']=='TEEIB'].iloc[0,3],\n",
    "    '工业':data_2009_NM[data_2009_NM['MSN']=='TEICB'].iloc[0,3],\n",
    "    '住宅':data_2009_NM[data_2009_NM['MSN']=='TERCB'].iloc[0,3],\n",
    "}\n",
    "\n",
    "\n",
    "data = pd.Series(x).reset_index(name='value').rename(columns={'index':'country'})\n",
    "data['angle'] = data['value']/data['value'].sum() * 2*pi\n",
    "#data['color'] = Category20c_6[len(x)]\n",
    "data['color'] = Category20[5]\n",
    "p = figure(plot_height=350, title=\"Pie Chart\", toolbar_location=None,\n",
    "           tools=\"hover\", tooltips=\"@country: @value\", x_range=(-0.5, 1.0))\n",
    "\n",
    "p.wedge(x=0, y=1, radius=0.4,\n",
    "        start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),\n",
    "        line_color=\"white\", fill_color='color', legend_field='country', source=data)\n",
    "\n",
    "p.axis.axis_label=None\n",
    "p.axis.visible=False\n",
    "p.grid.grid_line_color = None\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## the analyse of cleaner and renewable energy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## prediction by VAR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# PART II"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "307.667px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
